package com.sthz.facepay.mapper;

import com.sthz.facepay.model.Exchange;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.apache.ibatis.type.JdbcType;

public interface ExchangeMapper {
    @Delete({
        "delete from st_exchange",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into st_exchange (id, pid, ",
        "name, picture, exchange_time, ",
        "code, state)",
        "values (#{id,jdbcType=INTEGER}, #{pid,jdbcType=INTEGER}, ",
        "#{name,jdbcType=VARCHAR}, #{picture,jdbcType=VARCHAR}, #{exchange_time,jdbcType=TIMESTAMP}, ",
        "#{code,jdbcType=VARCHAR}, #{state,jdbcType=TINYINT})"
    })
    int insert(Exchange record);

    @InsertProvider(type=ExchangeSqlProvider.class, method="insertSelective")
    int insertSelective(Exchange record);

    @Select({
        "select",
        "id, pid, name, picture, exchange_time, code, state",
        "from st_exchange",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        /*@Result(column="pid", property="pid", jdbcType=JdbcType.INTEGER),*/
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="picture", property="picture", jdbcType=JdbcType.VARCHAR),
        @Result(column="exchange_time", property="exchange_time", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="code", property="code", jdbcType=JdbcType.VARCHAR),
        @Result(column="state", property="state", jdbcType=JdbcType.TINYINT),
        @Result(column="inid", property="interval", one=@One(select="com.sthz.facepay.mapper.IntervalMapper.getById",fetchType = FetchType.EAGER))
    })
    Exchange selectByPrimaryKey(Integer id);

    @UpdateProvider(type=ExchangeSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Exchange record);

    @Update({
        "update st_exchange",
        "set pid = #{pid,jdbcType=INTEGER},",
          "name = #{name,jdbcType=VARCHAR},",
          "picture = #{picture,jdbcType=VARCHAR},",
          "exchange_time = #{exchange_time,jdbcType=TIMESTAMP},",
          "code = #{code,jdbcType=VARCHAR},",
          "state = #{state,jdbcType=TINYINT}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Exchange record);
}